package com.xiyuan.controller.memoManage;

import com.xiyuan.pojo.result.Result;
import com.xiyuan.pojo.entity.MemoCategory;
import com.xiyuan.service.MemoCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/category")
public class MemoCategoryController {
    @Autowired
    private MemoCategoryService memoCategoryService;

    /**
     * 列表
     * @return
     */
    @GetMapping
    public Result<List<MemoCategory>> list(){
        return Result.success(memoCategoryService.getList());
    }

    /**
     * 新增
     * @param memoCategory
     * @return
     */
    @PostMapping
    public Result insert(@RequestBody @Validated(MemoCategory.Add.class) MemoCategory memoCategory){
        memoCategoryService.insert(memoCategory);
        return Result.success();
    }

    /**
     * 更新
     * @param memoCategory
     * @return
     */
    @PutMapping
    public Result update(@RequestBody @Validated(MemoCategory.Update.class) MemoCategory memoCategory){
        memoCategoryService.update(memoCategory);
        return Result.success();
    }

    /**
     * 查询详情
     * @param id
     * @return
     */
    @GetMapping("/detail")
    public Result<MemoCategory> detail(Integer id){
        MemoCategory result = memoCategoryService.findById(id);
        return Result.success(result);
    }

    @DeleteMapping
    public Result delete(Integer id){
        memoCategoryService.delete(id);
        return Result.success();
    }
}
